/**   
 * 项目名：化工企业安全生产信息化管理平台
 * 日期：    2020-03-17 14:00:30  
 * Copyright (c) 2015- -版权所有     
 */
package com.joysuch.wwyt.edu.controller;

import javax.validation.Valid;

import cn.zlg.common.springmvc.validate.constraints.NotNull;

import com.joysuch.wwyt.core.common.ajax.ResultBean;
import com.joysuch.wwyt.edu.bean.EduCourseStudyHistoryEditBean;
import com.joysuch.wwyt.edu.bean.EduCourseStudyHistoryListBean;
import static com.joysuch.wwyt.edu.bean.EduCourseStudyHistoryListBean.SearchEduCourseStudyHistory;
import com.joysuch.wwyt.edu.entity.EduCourseStudyHistory;
import com.joysuch.wwyt.edu.service.EduCourseStudyHistoryService;
import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/edu/course-study-history")
public class EduCourseStudyHistoryController {

    private static final Logger logger = LoggerFactory.getLogger(EduCourseStudyHistoryController.class);

    @Autowired
    private EduCourseStudyHistoryService eduCourseStudyHistoryService;

    @RequiresPermissions("edu:course:study:history:add")
    @RequestMapping("add")
    public Object add(@Valid @RequestBody EduCourseStudyHistoryEditBean entity) {
        eduCourseStudyHistoryService.add(entity);
        return ResultBean.success("");
    }

    @RequiresPermissions("edu:course:study:history:update")
    @RequestMapping("update")
    public Object update(@Valid @RequestBody EduCourseStudyHistoryEditBean entity) {
        if (entity.getId() == null) {
            return ResultBean.fail(102, "未指定主键");
        }
        eduCourseStudyHistoryService.update(entity);
        return ResultBean.success("");
    }

  //  @RequiresPermissions("edu:course:study:history")
    @RequestMapping("page")
    public Object page(Pageable page, SearchEduCourseStudyHistory condition) {
        Page<EduCourseStudyHistoryListBean> data = eduCourseStudyHistoryService.findByPage(page,condition);
        return ResultBean.pageData(data.getContent(), data.getTotalElements());
    }

  //  @RequiresPermissions("edu:course:study:history")
    @RequestMapping("select-page")
    public Object selectPage(Pageable page, SearchEduCourseStudyHistory condition) {
        Page<EduCourseStudyHistoryListBean> data = eduCourseStudyHistoryService.findByPage(page,condition);
        return ResultBean.pageData(data.getContent(), data.getTotalElements());
    }

    @RequiresPermissions("edu:course:study:history:delete")
    @RequestMapping("delete")
    public Object delete(Long id) throws Exception {
        eduCourseStudyHistoryService.delete(id);
        return ResultBean.success("");
    }

  //  @RequiresPermissions("edu:course:study:history")
    @RequestMapping("get")
    public Object getById(@Valid @NotNull(field="id") Long id) {
        return ResultBean.success(eduCourseStudyHistoryService.getById(id));
    }
}

